from itertools import groupby


class Solution:
    def countHomogenous(self, s: str) -> int:
        #用字典记录每一段的长度
        all_count = 0
        sum = 0
        flag = s[0] # 记录是否字符发生改变
        count = 0   # 记录相同字符在同区段的个数
        for char in s:
            if flag == char:
                count +=1
                all_count +=1
                if all_count == len(s):
                    sum += count * (count + 1) / 2
            else:
                print(count)
                sum += count *(count+1) / 2
                count = 1
                flag = char
                all_count += 1
                if all_count == len(s):
                    sum += count * (count + 1) / 2
        return int(sum % (10**9+7))

    def countHomogenous1(self, s: str) -> int:
        res = 0
        for k, g in groupby(s):
            n = len(list(g))
            res += (n + 1) * n // 2
        return res % (10 ** 9 + 7)

if __name__ == '__main__':
    s = "abbcccaa"
    solution = Solution()
    val = solution.countHomogenous(s)
    print(val)
